/**
 * @(#) ReqCelebration2Mediator.as
 *
 * @date		2009. 03. 19.
 * @version		1.0
 * @author		Park, Juneho
 * @description	경조사 신청 - Mediator
 * 				경조사를 신청하는 Presentation Logic을 관리 
 */
package com.skt.common_hr.congmoney2.view
{
	import com.skt.common_hr.common.Variables;
	import com.skt.common_hr.common.approval.RequestApprovalMediator;
	import com.skt.common_hr.common.components.CommonAlert;
	import com.skt.common_hr.common.memberselector.MemberSelectorMediator;
	import com.skt.common_hr.common.memberselector.MemberVO;
	import com.skt.common_hr.common.puremvc.CommonMediator;
	import com.skt.common_hr.congmoney2.CongMoney2Facade;
	import com.skt.common_hr.congmoney2.events.CelebrationEvent;
	import com.skt.common_hr.congmoney2.model.AccountProxy;
	import com.skt.common_hr.congmoney2.model.CelebrationApprovalProxy;
	import com.skt.common_hr.congmoney2.model.CelebrationCodeProxy;
	import com.skt.common_hr.congmoney2.model.CelebrationProxy;
	import com.skt.common_hr.congmoney2.model.CongMoneyWriteProxy;
	import com.skt.common_hr.congmoney2.model.FamilyProxy;
	import com.skt.common_hr.congmoney2.model.SupportStandardProxy;
	import com.skt.common_hr.congmoney2.model.vo.CelebrationCodeVO;
	import com.skt.common_hr.congmoney2.model.vo.CongFamilyVO;
	import com.skt.common_hr.congmoney2.model.vo.CongMoneyAccountVO;
	import com.skt.common_hr.congmoney2.model.vo.CongMoneyWriteVO;
	import com.skt.common_hr.congmoney2.view.components.CongFamily2View;
	import com.skt.common_hr.congmoney2.view.components.CongMoneyAccountControl;
	import com.skt.common_hr.congmoney2.view.components.ReqCelebrationView;
	import com.skt.common_hr.congmoney2.view.components.SupportStandard;
	import com.wcl.utils.ArrayHelper;
	import com.wcl.utils.DateUtil;
	
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.core.IFlexDisplayObject;
	import mx.managers.PopUpManager;
	
	import org.puremvc.as3.multicore.interfaces.INotification;

	public class ReqCelebration2Mediator extends CommonMediator
	{
		public static const NAME:String = "CongMoneyWriteMediator";
		
		
		public static const CLOSED_REQUEST_VIEW:String						= "closedRequestView";
 		private var bWaitingApproval:Boolean = false;
 		private var bWaitingExistData:Boolean = false;
		private var _currentKey:String = "";

		
		/**
		* 생성자
		* 
		* @param
		* @return void
		*/
        public function ReqCelebration2Mediator( viewComponent:Object )
        {
            super( NAME, viewComponent );
        }
 		
		/**
		* View를 초기화 한다.
		*	- View에 기본사항을 출력하고 data를 load
		* @param
		* @return void
		*/
 		override protected function initializeView():void
 		{
 			setEventListeners();
 			
 			
 			// 휴가 계산을 위한 공휴일 설정
 			//var holiProxy:CelebrationCodeProxy = facade.retrieveProxy(CelebrationCodeProxy.NAME) as CelebrationCodeProxy;
 			//view.holidays = holiProxy.holidays;
 			//for each(var d:Date in view.holidays) {
 			//	trace("공휴일 : " + d);
 			//} 
 		}
 		
 		private function setEventListeners():void
 		{
 			/* 
			
			
			view.addEventListener(ReqCelebrationView.CongAccount, onCongAccount);
			
			
			//view.addEventListener(ComboBoxEvent.SELECT_DATA, onChangedCode);
			//view.addEventListener(CongMoneyWriteEvent.UPDATE_DATA, onCongMoneyWriteUpdate);
			*/
			view.addEventListener(ReqCelebrationView.CongStandard, displaySupportStandard);//경조사지원기준
			view.addEventListener(ReqCelebrationView.CongClose, onCongClose);
			view.addEventListener(ReqCelebrationView.CHANGED_CELEBRRATION_CODE, onChangedCelebrationCode); // 
			
			view.addEventListener(CelebrationEvent.SAVE_REQESUT, onSaveRequest);				//임시저장 
			view.addEventListener(CelebrationEvent.APPROVAL_REQUEST, onApprovalRequest);		//승인요청
			
			view.addEventListener(ReqCelebrationView.CongCpernrChange, onClickSelectMember); 	// 대상자 변경
			view.addEventListener(ReqCelebrationView.CongFamilySelect, onClickChangeFamily);	// 사유발생자 변경.
 		}
 		
 		
 		override protected function clearView():void
 		{
 			trace("clear CongMoneyWriteMediator");
 		}
 		
  			
 		
 		
 		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Process MVC Messages
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		* 본 Class에서 처리해야할 Noti들을 등록한다.
		* 
		* @param
		* @return void
		*/
		override public function listNotificationInterests():Array 
		{
			return [
					CongMoney2Facade.LOAD_CELEBRATION_MODIFY_DETAIL_COMPLETE,
					CongMoney2Facade.LOAD_CELEBRATION_DETAIL_FAILED,
					CongMoney2Facade.LOAD_CONGMONEY_WRITE_COMPLETE,
					CongMoney2Facade.SAVE_CELEBRATION_COMPLETE,
					CongMoney2Facade.SAVE_CELEBRATION_FAILED,
					CongMoney2Facade.LOAD_CONGMONEY_WRITE_INITIAL,
					CongMoney2Facade.LOAD_FAMILY_INFO,
					CongMoney2Facade.LOAD_CELEBRATION_CODE_COMPLETE,
					CongMoney2Facade.LOAD_CELEBRATION_CODE_FAILED,
					CongMoney2Facade.LOAD_CONGMONEY_BANKA_COMPLETE,
					CongMoney2Facade.LOAD_CONGMONEY_BANKA_FAILED,
					CongMoney2Facade.LOAD_FAMILY_COMPLETE,
					CongMoney2Facade.LOAD_FAMILY_FAILED,
					CongMoney2Facade.LOAD_CONGMONEY_SELECTED_COMPLETE,
					CongMoney2Facade.LOAD_CONGMONEY_SAVE_FAILED,
					CongMoney2Facade.LOAD_DEFAULT_FAMILY_FAILED,
					CongMoney2Facade.LOAD_CONGMONEY_CORSNMONEY_COMPLETE,
					CongMoney2Facade.LOAD_CONGMONEY_CORSNMONEY_FAILED,
					CongMoney2Facade.SELECTED_FAMILY,
					CongMoney2Facade.MODIFIED_ACCOUNT,
					
					MemberSelectorMediator.SELECTED_MEMBER,
					RequestApprovalMediator.APPROVAL_CANCEL,
					RequestApprovalMediator.APPROVAL_COMPLETE
					];
		}
		

		/**
		* Noti별로 처리한다.
		* 
		* @param
		* @return void
		*/
		override public function handleNotification(note:INotification):void
		{
			
			switch(note.getName()) 
			{
				case CongMoney2Facade.LOAD_CONGMONEY_WRITE_INITIAL:
					bActivated = true;
					view.currentState = "";
					loadInitialData(note.getBody().pernr, note.getBody().name, note.getBody().gwarekey);
					break;
				case CongMoney2Facade.LOAD_CELEBRATION_MODIFY_DETAIL_COMPLETE:
					if(bActivated) {
						setLoadedDetailInfo( CelebrationProxy(note.getBody()).detailVO );
					}
					//onSelectedDataLoad(note.getBody() as CongMoneyWriteProxy);
					//view.callLater(onSelectedDataLoad,[note.getBody() as CongMoneyWriteProxy]);
					break;
				case CongMoney2Facade.LOAD_CELEBRATION_DETAIL_FAILED:
					trace("LoadCongmoneyWriteFailed");
					//AlertHelper.showMessage((note.getBody() as CongMoneyWriteProxy).loadFaultMessage);
					break;
				case CongMoney2Facade.SAVE_CELEBRATION_COMPLETE:
					//setStatusMessage("저장되었습니다.");
					
					CommonAlert.showMessage(commonFacade.bundle,"저장되었습니다.", null);
					if(bWaitingApproval) {
						/*
						s03.17 결재하지 않음 . 그냥 저장과 똑같이 설정   
						_currentKey = CelebrationProxy(note.getBody()).key; 
						view.dataProvider.GWAREKEY = _currentKey;
						execApproval(_currentKey);
 						*/
 												
 						clearView();
 						bActivated = false;
			 			facade.sendNotification(CLOSED_REQUEST_VIEW, this);
					}
					else {
			 			clearView();
 						bActivated = false;
			 			facade.sendNotification(CLOSED_REQUEST_VIEW, this);
			 		}
			 		bWaitingApproval = false;
					trace("saved completed");
					break;
				case CongMoney2Facade.SAVE_CELEBRATION_FAILED:
					bWaitingApproval = false;
					CommonAlert.showMessage(commonFacade.bundle, CelebrationProxy(note.getBody()).faultMessage, null);
					break;
				case CongMoney2Facade.LOAD_CELEBRATION_CODE_COMPLETE:
					setCelebrationCode(CelebrationCodeProxy(note.getBody()).codeList); 
					break;
				case CongMoney2Facade.LOAD_CELEBRATION_CODE_FAILED:
					//setStatusMessage("경조사유코드를 조회중 오류가 발생했습니다.");
					break;
				case CongMoney2Facade.LOAD_FAMILY_COMPLETE:
					setFamilyList(FamilyProxy(note.getBody()).family); 
					break;
				case CongMoney2Facade.LOAD_FAMILY_FAILED:
					//setStatusMessage("가족정보를 조회중 오류가 발생했습니다.");
					break;
				case CongMoney2Facade.LOAD_CONGMONEY_BANKA_COMPLETE:
					setBankList(note.getBody() as AccountProxy);
					trace("LOAD_CONGMONEY_BANKA_COMPLETE");
					break;
				case CongMoney2Facade.LOAD_CONGMONEY_BANKA_FAILED:
					trace("LoadCongmoneyBankaFailed");
					//AlertHelper.showMessage((note.getBody() as CongMoneyWriteProxy).bnksaFaultMessage);
					break;

				case CongMoney2Facade.SELECTED_FAMILY:
					onFamilyDataLoad(note.getBody() as CongFamilyVO);
					break;
				case MemberSelectorMediator.SELECTED_MEMBER:
					if(bActivated) {
						onMemberDataLoad(MemberSelectorMediator(note.getBody()).selectedMember);
					}
					break;
					
				case CongMoney2Facade.MODIFIED_ACCOUNT:
					//기타계좌 수정시 계좌관리  로드 
 					//bankaLoadData();
 					//loadBankInfo(view.dataProvider.CPERNR);
 					var subMedi:CongMoneyAccountMediator = facade.retrieveMediator(CongMoneyAccountMediator.NAME) as CongMoneyAccountMediator;
 					view.dataProvider.BANKL = subMedi.BANKL;
					view.dataProvider.BANKA = subMedi.BANKA;
 					view.dataProvider.BANKN = subMedi.BANKN;
 					view.dataProvider.EMFTX = subMedi.EMFTX;
 					var index:int = ArrayHelper.indexOf(view.accounts, "BNKSA", 2); 
					if(index>0) {
						var selectedAccount:CongMoneyAccountVO = view.accounts[index];
						selectedAccount.BANKL = subMedi.BANKL;
						selectedAccount.BANKA = subMedi.BANKA;
						selectedAccount.BANKN = subMedi.BANKN;
						selectedAccount.EMFTX = subMedi.EMFTX; 
					}
					trace(view.dataProvider.BANKA, view.dataProvider.BANKN,view.dataProvider.EMFTX );
					break;
					
				case CongMoney2Facade.LOAD_CONGMONEY_SELECTED_COMPLETE:
					onSelected(note.getBody() as CelebrationProxy);
					break;
				case CongMoney2Facade.LOAD_CONGMONEY_SAVE_FAILED:
					//경조신청 저장시 휴가중복일경우
					onSaveErroryMessage(note.getBody() as CongMoneyWriteProxy);
					break;
				
				case CongMoney2Facade.LOAD_DEFAULT_FAMILY_FAILED:
					trace("LoadDefaultFamilyFailed");
					CommonAlert.showMessage(commonFacade.bundle, (note.getBody() as FamilyProxy).defaultResultMessage);
					break;
				case CongMoney2Facade.LOAD_CONGMONEY_CORSNMONEY_COMPLETE:
					//onCorsnMoney(note.getBody() as CongMoneyWriteProxy);
					break;
				case CongMoney2Facade.LOAD_CONGMONEY_CORSNMONEY_FAILED:
					CommonAlert.showMessage(commonFacade.bundle, (note.getBody() as CongMoneyWriteProxy).corsnMoneyResultMessage);
					view.BETRG.text = "0";
 					view.ZWRTH.selectedValue = "";
					break;
				case RequestApprovalMediator.APPROVAL_COMPLETE:					// 결재 요청  성공
					bActivated = false;
		 			clearView();
 					bActivated = false;
		 			facade.sendNotification(CLOSED_REQUEST_VIEW, this);
					//facade.sendNotification(TrainingFacade.SUCCEED_REQ_TRAINING, this);
					break;
				case RequestApprovalMediator.APPROVAL_CANCEL:					// 결재 요청 취소
					bActivated = true;
		 			//clearView();
		 			//facade.sendNotification(CLOSED_REQUEST_VIEW, this);
					//cancelApproval(_currentKey);
					break;
				default:
					//trace(this.instanceID+"에서 처리 안된 Noti가 검출됨 : " + note.getBody());
					break;
			}
		}
		
		/**
		 * Proxy에서 DataLoad를 완료한 후 호출됨
		 *     - 조회상세보기
		 * @param
		 * @return void
		 */
 		private function setLoadedDetailInfo(vo:CongMoneyWriteVO):void
 		{
			view.dataProvider = vo;
			
			// s0317 경조사 확인에서 대리 신청은 없기로.. 
			if(vo.CPERNR!=Variables.myPernr) {
				//loadCodes(false);
				loadCodes(true);
			}
			else {
				loadCodes(true);
			}
			
			// 0401 경조사 진행확인에서 가족리스트 디폴트로 띄우지 않는다.
			loadFamilyList(vo.CPERNR);			
			loadBankInfo(vo.CPERNR);
 		}
		
		private function findCodeIndex(key:String, srcArr:ArrayCollection):int 
		{
			for(var i:int=0; i<srcArr.length; i++) {
				if(srcArr[i].data == key) {
					return i;
				}
			}
			return -1;
		}
		
		private function loadInitialData(pernr:String, name:String, gwarekey:String=""):void
		{
 			if(gwarekey!="") {
 				trace("modify data: " + gwarekey);
 				loadExistData(gwarekey);	//경조사신청(입력,업데이트)
 			}
 			else {
 				view.dataProvider = getDefaultData();
	 			
	 			loadCodes();		//사유콤보박스
	 			loadBankInfo(Variables.myPernr);
	 			loadFamilyList(Variables.myPernr);
 			}
		}
		
 		
		/**
		 * Proxy에서 DataLoad를 완료한 후 호출됨
		 *     - 계좌선택 콤보 load된 데이터를 화면에 출력
		 * @param
		 * @return void
		 */
 		private function setBankList(proxy:AccountProxy):void
 		{
 			view.accounts = proxy.AccountList;
 			
 			if(bWaitingExistData) {
				 				
 			}
 			else {
 				//view.clearAccountInfo();
 			}
 			bWaitingExistData = false;
 			
 		}

 		private function setCelebrationCode(list:ArrayCollection):void
 		{
 			view.celebrationCodeList = list;
 		}
 
 		private function setFamilyList(arr:ArrayCollection):void
 		{
			view.familyList = arr; 			
 		}
 		
 		private function getDefaultData():CongMoneyWriteVO
 		{
 			var dp:CongMoneyWriteVO = new CongMoneyWriteVO;
 			dp.IPERNR = dp.CPERNR = Variables.myPernr;
 			dp.INAME = dp.CNAME = Variables.myName;
 			dp.CODAT = DateUtil.todayNoTime();
 			dp.IDATE = DateUtil.todayNoTime();
 			dp.COSEL = "X";
 			dp.WAERS = "KRW";
 			
 			return dp;
 		}	
 
 
		private function execApproval(key:String):void
		{
 			var approval:RequestApprovalMediator = facade.retrieveMediator(RequestApprovalMediator.NAME) as RequestApprovalMediator;
 			if(approval==null) {
 				approval = new RequestApprovalMediator(view, "06");
 				facade.registerMediator(approval);
 			}
 			bActivated = false;
 			var appProxy:CelebrationApprovalProxy = facade.retrieveProxy(CelebrationApprovalProxy.NAME) as CelebrationApprovalProxy;
 			appProxy.key = key;
 			appProxy.dataProvider = tmpVO;
 			approval.execRequest(view, appProxy);
		}

		

		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Access Functions....
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
 		private function loadExistData(gwarekey:String):void
 		{
			var proxy:CelebrationProxy = facade.retrieveProxy(CelebrationProxy.NAME) as CelebrationProxy;
			bWaitingExistData = true;
			proxy.loadDetail(gwarekey);
 		}
 		
 		/**
		 * 경조사유 조회
		 * @param
		 * @return void
		 */
 		private function loadCodes(oneself:Boolean = true):void
 		{
			var proxy:CelebrationCodeProxy = facade.retrieveProxy(CelebrationCodeProxy.NAME) as CelebrationCodeProxy;
			proxy.loadCodes( oneself ? "" : "X");
 		}
 		
 		
 		/**
		 * 계좌선택 콤보
		 * @param
		 * @return void
		 */
 		private function loadBankInfo(pernr:String):void
 		{
			var accountProxy:AccountProxy = facade.retrieveProxy(AccountProxy.NAME) as AccountProxy;
			accountProxy.loadAccounts(pernr);
 		}
 
  		/**
		 * 가족사항 조회
		 * @param
		 * @return void
		 */
 		private function loadFamilyList(pernr:String):void
 		{
			var proxy:FamilyProxy = facade.retrieveProxy(FamilyProxy.NAME) as FamilyProxy;
			proxy.load(pernr);
 		}
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event handler (from View, Internal or....)
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
  		
 		/**
		 * 경조사 지원기준
		 * @param
		 * @return void
		 */
 		private function displaySupportStandard(event:Event):void
 		{
 			var proxy:SupportStandardProxy = facade.retrieveProxy(SupportStandardProxy.NAME) as SupportStandardProxy;
 			
 			var congStandardView:IFlexDisplayObject = PopUpManager.createPopUp(view, SupportStandard, true);
 			PopUpManager.centerPopUp(congStandardView);
 			(congStandardView as SupportStandard).setFocus();
 			SupportStandard(congStandardView).standardList = proxy.standardList;
 		}
 		
 		/**
		 * 대상자 변경
		 * @param
		 * @return void
		 */
 		private function onClickSelectMember(event:Event):void
 		{
			var mediator:MemberSelectorMediator;
			mediator = facade.retrieveMediator(MemberSelectorMediator.NAME) as MemberSelectorMediator;
			if(mediator==null) {
				mediator = new MemberSelectorMediator();
				facade.registerMediator(mediator);
			}
			mediator.exec(view.root);
			/*
 			if(congCpernrPop==null) {
 				congCpernrPop = PopUpManager.createPopUp(view, CongMoneyCpernrChange, true);
	 			PopUpManager.centerPopUp(congCpernrPop);
				pernrChangeMediator = new MemberSearchMediator(congCpernrPop);
				pernrChangeMediator.Cpernr = Variables.myPernr;
	 			facade.registerMediator(pernrChangeMediator);
	 		}else{
 				PopUpManager.addPopUp(congCpernrPop, view);
	 			pernrChangeMediator = facade.retrieveMediator(MemberSearchMediator.NAME) as MemberSearchMediator;
	 			pernrChangeMediator.Cpernr = Variables.myPernr;
	 			pernrChangeMediator.execute();
	 		}
	 		*/
 		}
 		
 		
 		/**
		 * 계좌관리팝업
		 * @param
		 * @return void
		 */
		private var accountPopUp:IFlexDisplayObject = null;
 		private function onCongAccount(event:Event):void
 		{
 			var accMediator:CongMoneyAccountMediator = facade.retrieveMediator(CongMoneyAccountMediator.NAME) as CongMoneyAccountMediator;
 			if(accMediator==null) {
	 			accountPopUp = PopUpManager.createPopUp(view, CongMoneyAccountControl, true);
	 			PopUpManager.centerPopUp(accountPopUp);
	 			accMediator = new CongMoneyAccountMediator(accountPopUp);
	 			facade.registerMediator(accMediator);
 			}
 			else {
 				PopUpManager.addPopUp(accountPopUp, view, true);
	 			accMediator = facade.retrieveMediator(CongMoneyAccountMediator.NAME) as CongMoneyAccountMediator;
 			}
 			(accountPopUp as CongMoneyAccountControl).setFocus();
 			accMediator.execute(view.dataProvider.CPERNR);
 		}
 		
 		
 		
		private var congFamilyView:IFlexDisplayObject = null;;
 		private function executeFamilyPopUp(filter:String = ""):void
 		{
 			var familyMediator:FamilyMediator=facade.retrieveMediator(FamilyMediator.NAME) as FamilyMediator;
 			if(familyMediator==null) {
	 			congFamilyView = PopUpManager.createPopUp(view, CongFamily2View, true);
	 			PopUpManager.centerPopUp(congFamilyView);
	 			familyMediator = new FamilyMediator(congFamilyView);
	 			facade.registerMediator(familyMediator);
 			}
 			else {
 				PopUpManager.addPopUp(congFamilyView, view, true);
 			}
			familyMediator.execute(view.dataProvider.CPERNR, filter);

			/*
 			var familyMediator:FamilyMediator;
 			if(congFamilyView==null) {
	 			congFamilyView = PopUpManager.createPopUp(view, CongFamilyView, true);
	 			PopUpManager.centerPopUp(congFamilyView);
	 			familyMediator = new FamilyMediator(congFamilyView);
	 			facade.registerMediator(familyMediator);
	 			familyMediator.execute(view.dataProvider.CPERNR);
 			}
 			else {
 				familyMediator = facade.retrieveMediator(FamilyMediator.NAME) as FamilyMediator;
 				PopUpManager.addPopUp(congFamilyView, view);
	 			familyMediator.execute(view.dataProvider.CPERNR);
 			}
 			*/
 		}
 		/**
		 * 경조사유변경시 경조금액조회
		 * @param
		 * @return void
		 */
 		private function onChangedCelebrationCode(event:Event):void
 		{
 			trace("onChangedCelebrationCode");
 			//var congProxy:CongMoneyWriteProxy = facade.retrieveProxy(CongMoneyWriteProxy.NAME) as CongMoneyWriteProxy;
			//congProxy.corsnMoneySearch(event.comData, event.subData); 
			var selectedType:CelebrationCodeVO = view.selectedCelebrationType;
			if(selectedType==null) {
				return;
			}
			view.dataProvider.CORSN	= selectedType.CORSN;
			view.dataProvider.ZTEXT = selectedType.ZTEXT;
        	view.dataProvider.BETRG = selectedType.BETRG;
				
    		if(selectedType.CODAY > 0 ) {	// 휴가 지급 가능 경조인 경우
    			view.showVacation(); 
    		}
    		else {
    			view.hideVacation();
    		} 
    		if(selectedType.ZWRTH == "X") {		// 화환지급대상이면
    			view.showFlower(); 
    		}
    		else {
    			view.hideFlower();
    			view.dataProvider.ZWRTH = "";
    		}
			if(selectedType.FAMILY != null) { 			
				var familyCount:uint = findFamily(selectedType.FAMILY);
				if(familyCount > 1) {
					//경조사 2명 이상에서 팝업 띄우기 - 강제로 한명만 띄우기 . 수정방법 없는데도? 0406 
					//executeFamilyPopUp(selectedType.FAMILY);
				}
				else if(familyCount==0) {
					CommonAlert.showMessage("CongMoney", "ALERT_NOT_FOUND_FAMILY");
				}
			}
			else {
				view.clearFamilyInfo();
			}
 		}
 		
		private function findFamily(code:String):uint
		{
			view.clearFamilyInfo();
			var count:uint = 0;
			for each(var fa:CongFamilyVO in view.familyList) {
				if(fa.FAMILY == code) {
					count++;
					view.dataProvider.COPER = fa.FNAME;
					view.dataProvider.COREG = fa.REGNO;
					view.dataProvider.FAMILY = fa.FAMILY;
					view.dataProvider.FTEXT = fa.ZTEXT;
				}
			}
			return count;
		}


 		private function onSaveRequest(event:CelebrationEvent):void
 		{
 			var proxy:CelebrationProxy = facade.retrieveProxy(CelebrationProxy.NAME) as CelebrationProxy;
 			proxy.save(event.gwarekey, event.writeVo);
 			trace('save: '+ event.gwarekey);
 		}
 		
 		private var tmpVO:CongMoneyWriteVO;
 		private function onApprovalRequest(event:CelebrationEvent):void
 		{
 			bWaitingApproval = true;
 			tmpVO = event.writeVo;
 			var proxy:CelebrationProxy = facade.retrieveProxy(CelebrationProxy.NAME) as CelebrationProxy;
 			proxy.save(event.gwarekey, event.writeVo, true);
 			trace('Approval: '+ event.gwarekey);
 		}
 		
  		
 		/**
		 * 경조사 저장수정
		 * @param
		 * @return void
		 */
		 /* 
 		private function onCongMoneyWriteUpdate(event:CongMoneyWriteEvent):void
 		{
 			//facade.removeMediator(CongMoneyWriteMediator.NAME);
 			var proxy:CongMoneyWriteProxy = facade.retrieveProxy(CongMoneyWriteProxy.NAME) as CongMoneyWriteProxy;
 			proxy.update(event.Fkey, event.writeVo);
 		}
 		 */
 		/**
		 * 경조사 입력팝업닫기
		 * @param
		 * @return void
		 */
 		private function onCongClose(event:Event):void
 		{
 			clearView();
 			bActivated = false;
 			facade.sendNotification(CLOSED_REQUEST_VIEW, this); 
 		}
 		 
 		//대상자변경
 		private function onMemberDataLoad(selectedMember:MemberVO):void
 		{
 			view.dataProvider.CPERNR = selectedMember.PERNR;
 			view.dataProvider.CNAME  = selectedMember.ENAME;
 			view.dataProvider.STEXT  = selectedMember.STEXT;
			// 경조사유코드리스트
			if(Variables.myPernr != selectedMember.PERNR) { 
				loadCodes(false); 	// 대리신청인 경우 false로 전달		 
 			}
 			else {
				loadCodes(true); 	// 본인신청일 겨우 		 
 			}
 			loadFamilyList(selectedMember.PERNR);
			loadBankInfo(selectedMember.PERNR);		//대상자변경시 계좌관리도 변경		
 			
 		}
 		 
 		 //사유발생자 가족 관계변경
 		private function onFamilyDataLoad(selectedFamily:CongFamilyVO):void
 		{
 			view.familyKdsvh  	= selectedFamily.KDSVH;
 			view.familyCode  	= selectedFamily.FAMILY;
 			view.dataProvider.FAMILY = selectedFamily.FAMILY;
 			view.dataProvider.COPER = selectedFamily.FNAME;		//사원 또는 지원자의 포맷된 이름
 			view.dataProvider.COREG = selectedFamily.REGNO;		//주민등록번호 (한국)
 			view.dataProvider.FTEXT = selectedFamily.ZTEXT;		//경조 가족관계 텍스트
 			/*
 			view.familyKdsvh  	= selectedFamily.KDSVH;
 			view.familyCode  	= selectedFamily.FAMILY;
 			view.FTEXT.text 	= selectedFamily.ZTEXT;		//경조 가족관계 텍스트
 			view.COPER.text  	= selectedFamily.FNAME;		//사원 또는 지원자의 포맷된 이름
 			view.COREG.text  	= selectedFamily.REGNO;		//주민등록번호 (한국)
 			*/
 		}
 		
 		 //경조사 상세보기 조회
 		private function onSelected(proxy:CelebrationProxy):void
 		{
 			var congProxy:CongMoneyWriteProxy = facade.retrieveProxy(CongMoneyWriteProxy.NAME) as CongMoneyWriteProxy;
			congProxy.load(proxy.key);
			
 			//corsnLoadData();
 			//bankaLoadData();
 		}
 		
 		//저장에러 메세지 휴가중복메세지
 		private function onSaveErroryMessage(proxy:CongMoneyWriteProxy):void
 		{
 			//AlertHelper.showMessage(proxy.saveErroryMessage);
 		}
 		
	
 		/**
		 * 경조 사유발생자 변경 버튼 클릭
		 * @param
		 * @return void
		 */
 		private function onClickChangeFamily(event:Event):void
 		{
 			executeFamilyPopUp();
		}




		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Utility Functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
        private function get view():ReqCelebrationView
        {
            return viewComponent as ReqCelebrationView;
        }
		
		
	}
}